package com.byxm.wlgw.service;

import java.sql.PreparedStatement;
import java.sql.ResultSet;
import java.util.ArrayList;
import java.util.List;

import com.byxm.wlgw.bean.KcxxBean;
import com.byxm.wlgw.common.DataBaseAccess;
import com.byxm.wlgw.query.KcxxQuery;



public class KcxxService {
	/**
	 * 库存信息Service
	 */
	
	/**
	 * 通过商品信息ID获取所有型号的库存信息
	 */
	KcxxQuery kcxxQuery = new KcxxQuery("kcxx");
	
	public List<KcxxBean> getLstKcxx(int spxxid){
		DataBaseAccess dba=null;
		List<KcxxBean> lstKcxx=new ArrayList<KcxxBean>();
		try {
			dba = new DataBaseAccess();
			ResultSet rs = dba.executeQuery(kcxxQuery.getKcxxByspxxid(spxxid));
			while (rs.next()) {
				KcxxBean kcxx=new KcxxBean();
				kcxx.setKcxxid(rs.getInt("kcxxid"));
				kcxx.setSpxxid(rs.getInt("spxxid"));
				kcxx.setKcsl(rs.getInt("kcsl"));
				kcxx.setXhid(rs.getInt("xhid"));
				kcxx.setSpxhnr(rs.getString("spxhnr"));
				lstKcxx.add(kcxx);
			}
			rs.close();
		} catch (Exception e) {
			e.printStackTrace();
		}finally{
			try {
				dba.releaseConnect();
			} catch (Exception e) {
				e.printStackTrace();
			}
		}
		return lstKcxx;
	}
	
	public boolean saveKcxx(KcxxBean bean) throws Exception{
		DataBaseAccess dba=null;
		PreparedStatement ps=null;
		int iFlag=0;
		try {
			dba=new DataBaseAccess();
			ps=dba.getPstmt(kcxxQuery.saveKcxxSql());
			ps.setInt(1, bean.getSpxxid());
			ps.setInt(2, bean.getXhid());
			ps.setInt(3, bean.getKcsl());
			iFlag=ps.executeUpdate();
			dba.commit();
			ps.close();
		} catch (Exception e) {
			dba.rollback();
			e.printStackTrace();
		}finally{
			dba.releaseConnect();
		}
		if(iFlag>0){
			return true;
		}else{
			return false;
		}
		
	}
	
}
